{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\62744\\Anaconda2\\lib\\site-packages\\pandas\\_libs\\__init__.py:3: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime\n",
      "C:\\Users\\62744\\Anaconda2\\lib\\site-packages\\pandas\\__init__.py:26: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import (hashtable as _hashtable,\n",
      "C:\\Users\\62744\\Anaconda2\\lib\\site-packages\\pandas\\core\\dtypes\\common.py:6: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import algos, lib\n",
      "C:\\Users\\62744\\Anaconda2\\lib\\site-packages\\pandas\\core\\util\\hashing.py:7: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import hashing, tslib\n",
      "C:\\Users\\62744\\Anaconda2\\lib\\site-packages\\pandas\\core\\indexes\\base.py:6: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import (lib, index as libindex, tslib as libts,\n",
      "C:\\Users\\62744\\Anaconda2\\lib\\site-packages\\pandas\\core\\indexes\\datetimelike.py:28: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs.period import Period\n",
      "C:\\Users\\62744\\Anaconda2\\lib\\site-packages\\pandas\\core\\sparse\\array.py:32: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  import pandas._libs.sparse as splib\n",
      "C:\\Users\\62744\\Anaconda2\\lib\\site-packages\\pandas\\core\\window.py:36: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  import pandas._libs.window as _window\n",
      "C:\\Users\\62744\\Anaconda2\\lib\\site-packages\\pandas\\core\\groupby.py:66: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import lib, groupby as libgroupby, Timestamp, NaT, iNaT\n",
      "C:\\Users\\62744\\Anaconda2\\lib\\site-packages\\pandas\\core\\reshape\\reshape.py:30: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import algos as _algos, reshape as _reshape\n",
      "C:\\Users\\62744\\Anaconda2\\lib\\site-packages\\pandas\\io\\parsers.py:43: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  import pandas._libs.parsers as parsers\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "import numpy as np\n",
    "import scipy.sparse as ss\n",
    "import scipy.io as sio\n",
    "\n",
    "#保存数据\n",
    "import cPickle\n",
    "\n",
    "from sklearn.preprocessing import normalize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13418\n"
     ]
    }
   ],
   "source": [
    "#读取训练集和测试集中出现过的事件列表\n",
    "elist = cPickle.load(open(\"PE_eventIndex.pkl\", 'rb'))\n",
    "numberevents = len(elist)\n",
    "\n",
    "print(numberevents)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#活动活跃度\n",
    "eventPopularity = ss.dok_matrix((numberevents, 1))\n",
    "    \n",
    "f = open(\"event_attendees.csv\", 'rb')\n",
    "\n",
    "#字段：event_id,yes, maybe, invited, and no\n",
    "f.readline() # skip header\n",
    "\n",
    "for line in f:\n",
    "    cols = line.strip().split(\",\")\n",
    "    eventId = str(cols[0])   #event_id\n",
    "    if elist.has_key(eventId):\n",
    "        i = elist[eventId]  #事件索引\n",
    "        \n",
    "        #yes - no\n",
    "        eventPopularity[i, 0] = \\\n",
    "          len(cols[1].split(\" \")) - len(cols[4].split(\" \"))\n",
    "    \n",
    "f.close()\n",
    "    \n",
    "eventPopularity = normalize(eventPopularity, norm=\"l1\",\n",
    "     copy=False)\n",
    "sio.mmwrite(\"EA_eventPopularity\", eventPopularity)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ 0.],\n",
       "        [-1.],\n",
       "        [ 1.],\n",
       "        ...,\n",
       "        [ 1.],\n",
       "        [ 1.],\n",
       "        [ 0.]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eventPopularity.todense()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
